<?php


class User extends database {

    function checkUser($uid, $oauth_provider, $username, $email) 
	{
		$this->setQuerry("SELECT * FROM `nguoidung` WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
		$result = $this->loadAllRow();
        if (!empty($result)) {
            # User is already present
        } else {
            #user not present. Insert a new Record
            $this->setQuerry("INSERT INTO `nguoidung` (TenHienThi, Email, KickHoat, oauth_uid, oauth_provider) VALUES ('$username', '$email', '1','$uid', '$oauth_provider')");
			$this->querry();
			
            $this->setQuerry("SELECT * FROM `nguoidung` WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
            $result = $this->loadAllRow();
            return $result;
        }
        return $result;
    }

    function checkUserGoogle($uid, $oauth_provider, $username, $email)
	{

        $this->setQuerry("SELECT * FROM `nguoidung` WHERE Email = '$email' and oauth_provider = '$oauth_provider'");
        $result = $this->loadAllRow();
        if (!empty($result)) {
            # User is already present
        } else {
            $this->setQuerry("INSERT INTO `nguoidung` (TenHienThi, Email, KickHoat, oauth_uid, oauth_provider) VALUES ('$username', '$email', '1','$uid', '$oauth_provider')");
			$this->querry();
            $this->setQuerry("SELECT * FROM `nguoidung` WHERE Email = '$email' and oauth_provider = '$oauth_provider'");
            $result = $this->loadAllRow();
            return $result;
        }
        return $result;
    }

}

?>
